package com.gy.hsim.bservice.shieldmsg.restful;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gy.hsim.bservice.framework.bean.BaseReponse;
import com.gy.hsim.bservice.framework.bean.ErrorMsg;
import com.gy.hsim.bservice.framework.enums.MessageResultEnum;
import com.gy.hsim.bservice.framework.restful.BaseController;
import com.gy.hsim.bservice.shieldmsg.bean.PublicNOShieldReq;
import com.gy.hsim.bservice.shieldmsg.service.ShieldPublicMsgService;

/**
 * 
 * @ClassName: SheldMsgController 
 * @Description: 屏蔽关注公众号的消息 
 * @author Lee 
 * @date 2015-1-19 上午11:11:02
 */
@Controller
public class SheldPublicMsgController extends BaseController {

	private static final Logger log = LoggerFactory
			.getLogger(SheldPublicMsgController.class);

	@Autowired
	private ShieldPublicMsgService shieldMsgService;


	/**
	 * 屏蔽/不屏蔽系统公众号 消息 请求URL: http://localhost:9090/hsim-bservice/shieldPublicMsg
	 * 
	 * @param request
	 * @param response
	 * @return 响应返回实体类，含返回码、响应消息
	 */

	@RequestMapping(value = "/shieldPublicMsg", method = RequestMethod.POST)
	public @ResponseBody
	BaseReponse shieldPublicMsg(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		
		JSONObject object = (JSONObject)request.getAttribute("object");
		
		PublicNOShieldReq req = JSON.toJavaObject(object, PublicNOShieldReq.class);
		
		BaseReponse resp = new BaseReponse();
	
		ErrorMsg errormsg = new ErrorMsg();
		
		boolean issuccess = shieldMsgService.update(req,errormsg);

		if (issuccess) {

			resp.setRetCode(MessageResultEnum.EXEC_SUCCESS.getRetCode());

			resp.setMessage(MessageResultEnum.EXEC_SUCCESS.getMessage());

		} else {
			resp.setRetCode(MessageResultEnum.EXEC_FAILD.getRetCode());

			if (errormsg.getErrormsg() != null && !"".equals(errormsg.getErrormsg())) {
				resp.setMessage(errormsg.getErrormsg());
			} else {
				resp.setMessage(MessageResultEnum.EXEC_FAILD.getMessage());
			}
		}

		return resp;

	}
	

}
